<?php if(!defined("HDPHP_PATH"))exit;C("SHOW_NOTICE",FALSE);?> <!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>添加商品类型</title>
	<script type='text/javascript' src='http://localhost/dshop/hdphp/hdphp/Extend/Org/Jquery/jquery-1.8.2.min.js'></script>
<link href='http://localhost/dshop/hdphp/hdphp/../hdjs/css/hdjs.css' rel='stylesheet' media='screen'>
<script src='http://localhost/dshop/hdphp/hdphp/../hdjs/js/hdjs.js'></script>
<script src='http://localhost/dshop/hdphp/hdphp/../hdjs/js/slide.js'></script>
<script src='http://localhost/dshop/hdphp/hdphp/../hdjs/org/cal/lhgcalendar.min.js'></script>
<script type='text/javascript'>
		HOST = 'http://localhost';
		ROOT = 'http://localhost/dshop';
		WEB = 'http://localhost/dshop/index.php';
		URL = 'http://localhost/dshop/index.php?a=Admin&c=Goods&m=edit&gid=29';
		HDPHP = 'http://localhost/dshop/hdphp/hdphp';
		HDPHPDATA = 'http://localhost/dshop/hdphp/hdphp/Data';
		HDPHPTPL = 'http://localhost/dshop/hdphp/hdphp/Lib/Tpl';
		HDPHPEXTEND = 'http://localhost/dshop/hdphp/hdphp/Extend';
		APP = 'http://localhost/dshop/index.php?a=Admin';
		CONTROL = 'http://localhost/dshop/index.php?a=Admin&c=Goods';
		METH = 'http://localhost/dshop/index.php?a=Admin&c=Goods&m=edit';
		GROUP = 'http://localhost/dshop/hd';
		TPL = 'http://localhost/dshop/hd/Tshop/Admin/Tpl';
		CONTROLTPL = 'http://localhost/dshop/hd/Tshop/Admin/Tpl/Goods';
		STATIC = 'http://localhost/dshop/Static';
		PUBLIC = 'http://localhost/dshop/hd/Tshop/Admin/Tpl/Public';
		HISTORY = 'http://localhost/dshop/index.php?a=Admin&c=Goods&m=index&page=3';
		HTTPREFERER = 'http://localhost/dshop/index.php?a=Admin&c=Goods&m=index&page=3';
</script>
</head>
<body> 
	<form method="post" class="hd-form" enctype="multipart/form-data">
	<input type="hidden" name="gid" value="<?php echo $field['gid'];?>">
	<div class="wrap">
				<div class="menu_list">
					<ul>
						<li>
							<a href="<?php echo U('index');?>">
								商品列表
							</a>
						</li>
						<li>
							<a href="javascript:;" class="action">
								修改商品
							</a>
						</li>
					</ul>
				</div>

				<div class="tab">
					<ul class="tab_menu">
						<li lab="base"><a href="javascript:;">基本信息</a></li>
						<li lab="content"><a href="javascript:;">详细信息</a></li>
						<li lab="pic"><a href="javascript:;">图片</a></li>
					</ul>
					<div class="tab_content">
						<div id="base">
							<table class="table1">
								<tr>
									<th>名称</th>
									<td><input type="text" name="gname" class="w300" value="<?php echo $field['gname'];?>"></td>
								</tr>
								
								<tr>
									<th>属性</th>
									<td>
										<label><input type="checkbox"   name="flag[]" value="推荐">推荐</label>
										<label><input type="checkbox"   name="flag[]" value="置顶">置顶</label>
										<script type="text/javascript">
										var f="<?php echo $field['flag'];?>",flag=f.split(",");
										$(":checkbox").each(function(){
											var v=$(this).val();
											for(var i in flag){
												if(flag[i]==v){
													$(this).attr('checked','checked');
												}
											}
										})
										</script>
									</td>
								</tr>
								<tr>
									<th>栏目</th>
									<td>
										<select name="cid">
											<?php $hd["list"]["cat"]["total"]=0;if(isset($category) && !empty($category)):$_id_cat=0;$_index_cat=0;$lastcat=min(1000,count($category));
$hd["list"]["cat"]["first"]=true;
$hd["list"]["cat"]["last"]=false;
$_total_cat=ceil($lastcat/1);$hd["list"]["cat"]["total"]=$_total_cat;
$_data_cat = array_slice($category,0,$lastcat);
if(count($_data_cat)==0):echo "";
else:
foreach($_data_cat as $key=>$cat):
if(($_id_cat)%1==0):$_id_cat++;else:$_id_cat++;continue;endif;
$hd["list"]["cat"]["index"]=++$_index_cat;
if($_index_cat>=$_total_cat):$hd["list"]["cat"]["last"]=true;endif;?>

											<option value="<?php echo $cat['cid'];?>" <?php if($field['cid']==$cat['cid']){?> selected="" <?php }?> ><?php echo $cat['_name'];?></option>
											<?php $hd["list"]["cat"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>	
										</select>
									</td>
								</tr>
					<!-- 库存表数据更改 --> 
								<tr>
									<th>属性</th>
									<td>
										<table>
											<?php $hd["list"]["goodsattr"]["total"]=0;if(isset($stock) && !empty($stock)):$_id_goodsattr=0;$_index_goodsattr=0;$lastgoodsattr=min(1000,count($stock));
$hd["list"]["goodsattr"]["first"]=true;
$hd["list"]["goodsattr"]["last"]=false;
$_total_goodsattr=ceil($lastgoodsattr/1);$hd["list"]["goodsattr"]["total"]=$_total_goodsattr;
$_data_goodsattr = array_slice($stock,0,$lastgoodsattr);
if(count($_data_goodsattr)==0):echo "";
else:
foreach($_data_goodsattr as $key=>$goodsattr):
if(($_id_goodsattr)%1==0):$_id_goodsattr++;else:$_id_goodsattr++;continue;endif;
$hd["list"]["goodsattr"]["index"]=++$_index_goodsattr;
if($_index_goodsattr>=$_total_goodsattr):$hd["list"]["goodsattr"]["last"]=true;endif;?>

											<tr>
												<th><?php echo $goodsattr['attr_name'];?></th>
												<td><?php echo $goodsattr['html'];?></td>
											</tr>
											<?php $hd["list"]["goodsattr"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>
										</table>
									</td>
								</tr>
								<tr>
									<th>规格</th>
									<td>
										<table>
											<thead>

											<tr>
											<?php $hd["list"]["spec"]["total"]=0;if(isset($specStock['attrClassData']) && !empty($specStock['attrClassData'])):$_id_spec=0;$_index_spec=0;$lastspec=min(1000,count($specStock['attrClassData']));
$hd["list"]["spec"]["first"]=true;
$hd["list"]["spec"]["last"]=false;
$_total_spec=ceil($lastspec/1);$hd["list"]["spec"]["total"]=$_total_spec;
$_data_spec = array_slice($specStock['attrClassData'],0,$lastspec);
if(count($_data_spec)==0):echo "";
else:
foreach($_data_spec as $key=>$spec):
if(($_id_spec)%1==0):$_id_spec++;else:$_id_spec++;continue;endif;
$hd["list"]["spec"]["index"]=++$_index_spec;
if($_index_spec>=$_total_spec):$hd["list"]["spec"]["last"]=true;endif;?>

												<td><?php echo $spec['attr_name'];?></td>
											<?php $hd["list"]["spec"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>	
												<td>库存</td>
												<td>价格</td>
												<td>货号</td> 
												<td><a href="javascript:;" onclick="addStock(this)">添加（+）</a></td>
											</tr>
											</thead>
											<tbody id="tbody">
										<?php $hd["list"]["html"]["total"]=0;if(isset($specStock['htmlData']) && !empty($specStock['htmlData'])):$_id_html=0;$_index_html=0;$lasthtml=min(1000,count($specStock['htmlData']));
$hd["list"]["html"]["first"]=true;
$hd["list"]["html"]["last"]=false;
$_total_html=ceil($lasthtml/1);$hd["list"]["html"]["total"]=$_total_html;
$_data_html = array_slice($specStock['htmlData'],0,$lasthtml);
if(count($_data_html)==0):echo "";
else:
foreach($_data_html as $key=>$html):
if(($_id_html)%1==0):$_id_html++;else:$_id_html++;continue;endif;
$hd["list"]["html"]["index"]=++$_index_html;
if($_index_html>=$_total_html):$hd["list"]["html"]["last"]=true;endif;?>

												<?php echo $html;?>
										<?php $hd["list"]["html"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>	

											</tbody>
											<script type="text/javascript">
													function addStock(obj){
														var html=$('.btn').eq(0).clone().find("[type='hidden']").remove().end();
														$('#tbody').append(html);
													}
													function removeStock(obj){
														var index=$('.btn').index();
														if(index>0){
															$(obj).parents(".btn").remove();
														}
													}

											</script>
										</table>
									</td>
								</tr>
	

								 <?php if(!$specStock){?>
								<tr>
									<th>价格</th>
									<td><input type="text" name="price" value="<?php echo $field['price'];?>" class="w300">
										
									</td>
								</tr>
								<tr>
									<th>库存</th>
									<td><input type="text" name="stock" value="<?php echo $field['stock'];?>" class="w300"></td>
								</tr>
							<?php }?>
								<tr>
									<th>关键词</th>
									<td><input type="text" name="keywords" value="<?php echo $field['keywords'];?>" class="w300"></td>
								</tr>
								<tr>
									<th>描述</th>
									<td>
										<textarea name="description" class="w400 h100"><?php echo $field['description'];?></textarea>
									</td>
								</tr>
							</table>
						</div>
						<div id="content">
							<table class="table1">
								<tr>
									<th class="w100">内容</th>
									<td><script type="text/javascript" charset="utf-8" src="http://localhost/dshop/hdphp/hdphp/Extend/Org/Ueditor/ueditor.config.js"></script><script type="text/javascript" charset="utf-8" src="http://localhost/dshop/hdphp/hdphp/Extend/Org/Ueditor/ueditor.all.min.js"></script><script type="text/javascript">UEDITOR_HOME_URL="http://localhost/dshop/hdphp/hdphp/Extend/Org/Ueditor/"</script><script id="hd_body" name="body" type="text/plain"><?php echo $field['body'];?></script>
        <script type='text/javascript'>
        $(function(){
                var ue = UE.getEditor('hd_body',{
                imageUrl:'http://localhost/dshop/index.php?a=Admin&c=Goods&gid=29&m=ueditor_upload&g=Tshop&water=0&uploadsize=2000000&maximagewidth=false&maximageheight=false'//处理上传脚本
                ,zIndex : 0
                ,autoClearinitialContent:false
                ,initialFrameWidth:"100%" //宽度1000
                ,initialFrameHeight:"300" //宽度1000
                ,autoHeightEnabled:false //是否自动长高,默认true
                ,autoFloatEnabled:false //是否保持toolbar的位置不动,默认true
                ,maximumWords:2000 //允许的最大字符数
                ,readonly : false //编辑器初始化结束后,编辑区域是否是只读的，默认是false
                ,wordCount:true //是否开启字数统计
                ,imagePath:''//图片修正地址
                , toolbars:[
            ['fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe','insertcode', 'pagebreak', 'template', 'background', '|',
                'horizontal', 'date', 'time', 'spechars',  'wordimage', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                'print', 'preview', 'searchreplace']
            ]//工具按钮
                , initialStyle:'p{line-height:1em; font-size: 14px; }'
            });
        })
        </script></td>
								</tr>
								<tr>
									<th class="w100">服务</th>
									<td><input type="text" name='service' value="<?php echo $field['service'];?>"></td>
								</tr>
								<tr>
									<th class="w100">查看次数</th>
									<td><input type="text" name="click" value="<?php echo $field['click'];?>"></td>
								</tr>
								<tr>
									<th class="w100">发表时间</th>
									<td class="h150"><input type="text" id="addtime" name="addtime" value="<?php echo $field['addtime'];?>"></td>
								</tr>
								<script type="text/javascript">
									$('#addtime').calendar({format: 'yyyy/MM/dd HH:mm:ss'});
								</script>
							</table>
						</div>
						<div id="pic">
							<table class="table1">
								<tr>
									<th class="w100">首页图</th>
									<td >
										<input type="file" name="index_pic">
										<img src="http://localhost/dshop/<?php echo $field['index_pic'];?>"  class="w150 h150">
										<input type="hidden" name="index_pic" value="<?php echo $field['index_pic'];?>">
									</td>
								</tr>
								<tr>
									<th class="w100">列表图</th>
									<td >
										<input type="file" name="list_pic">
										<img src="http://localhost/dshop/<?php echo $field['list_pic'];?>"  class="w100 h100">
										<input type="hidden" name="list_pic" value="<?php echo $field['list_pic'];?>">
									</td>
								</tr>
								<tr>
									<th class="w100">添加内容页图</th>
									<td >
										<ul id="button">
											<li><input  type="file" name="pic[]"><button type="button" id="but1"  class="hd-cancel">添加</button></li>
										</ul>

									</td> 
								</tr>
								<tr>
									<th class="w100">已有图</th>
									<td >
										<ul id="pic">
											
											<?php $hd["list"]["pic"]["total"]=0;if(isset($pic) && !empty($pic)):$_id_pic=0;$_index_pic=0;$lastpic=min(1000,count($pic));
$hd["list"]["pic"]["first"]=true;
$hd["list"]["pic"]["last"]=false;
$_total_pic=ceil($lastpic/1);$hd["list"]["pic"]["total"]=$_total_pic;
$_data_pic = array_slice($pic,0,$lastpic);
if(count($_data_pic)==0):echo "";
else:
foreach($_data_pic as $key=>$pic):
if(($_id_pic)%1==0):$_id_pic++;else:$_id_pic++;continue;endif;
$hd["list"]["pic"]["index"]=++$_index_pic;
if($_index_pic>=$_total_pic):$hd["list"]["pic"]["last"]=true;endif;?>

											<li>
												<img src="http://localhost/dshop/<?php echo $pic['medium'];?>" class="w200" ><span pid="<?php echo $pic['pid'];?>">x</span>
											</li>

											<?php $hd["list"]["pic"]["first"]=false;
endforeach;
endif;
else:
echo "";
endif;?>
										</ul>
									</td>
								</tr>
								
							</table> 
						</div>
					</div>
				</div>
				<div class='position-bottom'>
					<input type="submit" value="确定" class='hd-success'>
				</div>
	</div>
	</form>
</body>
<script type="text/javascript">
	$(function(){
		$('#pic li span').click(function(){
			var pid=$(this).attr('pid');
			$.post("<?php echo U('pic');?>",{"pid":pid});
			$(this).parent('li').remove();
		})
	})
	$(function(){
		var data='<li><input type="file" name="pic[]"><button id="but" type="button"  class="hd-cancel">删除</button></li>';
		$("#but1").click(function(){
			$(this).parent().append(data);
		})
		$("#but").live('click',function(){
			$(this).parent('li').remove();
		})

	})
// </script>
<style type="text/css">
	ul#pic li{
		position: relative;
		width: 200px;
		margin:5px 20px;
		border:1px solid #ccc;
	}
	ul#pic li span{
		position: absolute;
		display: block;
		right: 5px;
		top: 0px;
		font-size: 20px;
		cursor: pointer;
		color: red;
	}
</style>
</html>